package com.blog.Bard.base.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.blog.Bard.base.dao.BardDictDao;
import com.blog.Bard.base.pojo.BardDict;
import com.blog.Bard.common.service.BaseServiceImpl;
import com.blog.Bard.common.util.Pager;

@Service
@Transactional
public class BardDictServiceImpl extends BaseServiceImpl implements BardDictService {

	@Autowired
	private BardDictDao bardDictDao;

	@Override
	public List<BardDict> findAll() throws Exception {
		return bardDictDao.findAll();
	}

	@Override
	public Pager pageList(Map<String, Object> params) throws Exception {
		Integer pageNo = (Integer)params.get("pageNo");
		Integer pagesize = (Integer)params.get("pagesize");

		StringBuilder sql = new StringBuilder();
		List<Object> args = new ArrayList<Object>();
		
		sql.append(" select * from bardDict \n");
		
		return bardDictDao.getPagerBySql(sql.toString(), pageNo, pagesize, args.toArray());
	}

	@Override
	public void save(BardDict t) throws Exception {
		Integer id = t.getId();
		if(id!=null) {
			String dictCode = t.getDictCode();
			String dictValue = t.getDictValue();
			String dictType = t.getDictType();
			String desc = t.getDictDesc();
			Integer status = t.getDictStatus();
			Integer seq = t.getSeq();
			bardDictDao.updateDict(dictCode, dictValue, dictType, desc, status, seq, id);
		}else {
			bardDictDao.save(t);
		}
	}

	@Override
	public BardDict getOne(Integer id) throws Exception {
		return bardDictDao.getOne(id);
	}

	@Override
	public void del(Integer id) throws Exception {
		bardDictDao.deleteById(id);
	}
	
}
